#ifndef __EZFB_BASIC_H__
#define __EZFB_BASIC_H__

#ifndef __EZFB_EZFB_H__
#error Please include ezfb.h first!
#endif//__EZFB_EZFB_H__

typedef struct tagSURFACE {
	LONG			cx;
	LONG			cy;
	LONG			lnBitPerPixel;
	LONG			lnBytePerLine;
	LONG			lnTotalBytes;
	LPVOID			lpBits;
} SURFACE, *LPSURFACE;

EXTERN		SURFACE		sfScreen, sfBuffer;

STATIC INLINE
VOID		EZFBAPI		__SetPixel(
						LPSURFACE lpSurface,
						LONG x,
						LONG y,
						COLORREF crColor
						) {
	if (x < 0 || y < 0 || x >= lpSurface->cx || y >= lpSurface->cy)
		return;
#if BITS_PER_PIXEL == BPP_32
	LPDWORD lpPixel	= (LPDWORD)((LPBYTE)lpSurface->lpBits + y * lpSurface->lnBytePerLine) + x;
	*lpPixel	= (DWORD)crColor;
#endif
#if BITS_PER_PIXEL == BPP_24
	LPBYTE	lpPixel = (LPBYTE)lpSurface->lpBits + y * lpSurface->lnBytePerLine + x * 3;
	lpPixel[0]	= (BYTE)((crColor & 0x000000FF) >> 0x00);
	lpPixel[1]	= (BYTE)((crColor & 0x0000FF00) >> 0x08);
	lpPixel[2]	= (BYTE)((crColor & 0x00FF0000) >> 0x10);
#endif
#if BITS_PER_PIXEL == BPP_16
	LPWORD	lpPixel	= (LPWORD)((LPBYTE)lpSurface->lpBits + y * lpSurface->lnBytePerLine) + x;
	*lpPixel	= (WORD)(crColor & 0x0000FFFF);
#endif
}

STATIC INLINE
COLORREF	EZFBAPI		__GetPixel(
						LPSURFACE lpSurface,
						LONG x,
						LONG y
						) {
	if (x < 0 || y < 0 || x >= lpSurface->cx || y >= lpSurface->cy)
		return 0x00000000;
#if BITS_PER_PIXEL == BPP_32
	LPDWORD lpPixel	= (LPDWORD)((LPBYTE)lpSurface->lpBits + y * lpSurface->lnBytePerLine) + x;
	return *lpPixel;
#endif
#if BITS_PER_PIXEL == BPP_24
	LPBYTE	lpPixel = (LPBYTE)lpSurface->lpBits + y * lpSurface->lnBytePerLine + x * 3;
	return ((DWORD)lpPixel[2] << 0x10) | ((DWORD)lpPixel[1] << 0x08) | ((DWORD)lpPixel[0] << 0x00);
#endif
#if BITS_PER_PIXEL == BPP_16
	LPWORD	lpPixel	= (LPWORD)((LPBYTE)lpSurface->lpBits + y * lpSurface->lnBytePerLine) + x;
	return (DWORD)*lpPixel;
#endif
}

#endif//__EZFB_BASIC_H__
